// Decompiled by DJ v3.10.10.93 Copyright 2007 Atanas Neshkov  Date: 27/11/2008 23:00:01
// Home Page: http://members.fortunecity.com/neshkov/dj.html  http://www.neshkov.com/dj.html - Check often for new version!
// Decompiler options: packimports(3) 
// Source File Name:   StartDialog.java

package reversi;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;

// Referenced classes of package reversi:
//            MainWindow

public class StartDialog extends JDialog
    implements ActionListener
{

    public StartDialog(Frame frame)
    {
        super(frame);
        txtAlgorithm = new JTextField[2];
        btnFirstPlayer = new JRadioButton[2];
        startPressed = false;
        turnLength = 0;
        setTitle("Game settings");
        setModal(true);
        JPanel jpanel = new JPanel();
        GridBagConstraints gridbagconstraints = new GridBagConstraints();
        jpanel.setLayout(new GridBagLayout());
        gridbagconstraints.fill = 0;
        gridbagconstraints.ipadx = 10;
        Box box = Box.createHorizontalBox();
        JLabel jlabel = new JLabel("Duration of a turn (s):");
        box.add(jlabel);
        box.add(Box.createHorizontalStrut(10));
        txtTurnLength = new JTextField(3);
        txtTurnLength.setText("10");
        box.add(txtTurnLength);
        box.add(Box.createHorizontalGlue());
        GridBagConstraints _tmp = gridbagconstraints;
        gridbagconstraints.gridwidth = 0;
        gridbagconstraints.insets.bottom = 10;
        jpanel.add(box, gridbagconstraints);
        ButtonGroup buttongroup = new ButtonGroup();
        gridbagconstraints.insets.bottom = 0;
        gridbagconstraints.gridwidth = 1;
        jpanel.add(new JLabel("Starter"), gridbagconstraints);
        GridBagConstraints _tmp1 = gridbagconstraints;
        gridbagconstraints.gridwidth = 0;
        jpanel.add(new JLabel("Algorithm"), gridbagconstraints);
        gridbagconstraints.gridwidth = 1;
        btnFirstPlayer[0] = new JRadioButton(MainWindow.icons[2]);
        jpanel.add(btnFirstPlayer[0], gridbagconstraints);
        btnFirstPlayer[0].setBorderPainted(true);
        btnFirstPlayer[0].setHorizontalAlignment(0);
        btnFirstPlayer[0].setVerticalAlignment(0);
        buttongroup.add(btnFirstPlayer[0]);
        GridBagConstraints _tmp2 = gridbagconstraints;
        gridbagconstraints.gridwidth = 0;
        jpanel.add(txtAlgorithm[0] = new JTextField(15), gridbagconstraints);
        gridbagconstraints.gridwidth = 1;
        gridbagconstraints.insets.bottom = 10;
        btnFirstPlayer[1] = new JRadioButton(MainWindow.icons[3]);
        jpanel.add(btnFirstPlayer[1], gridbagconstraints);
        btnFirstPlayer[1].setBorderPainted(true);
        btnFirstPlayer[1].setHorizontalAlignment(0);
        btnFirstPlayer[1].setVerticalAlignment(0);
        buttongroup.add(btnFirstPlayer[1]);
        GridBagConstraints _tmp3 = gridbagconstraints;
        gridbagconstraints.gridwidth = 0;
        jpanel.add(txtAlgorithm[1] = new JTextField(15), gridbagconstraints);
        JPanel jpanel1 = new JPanel();
        btnStart = new JButton("Start");
        btnStart.setActionCommand("start");
        btnStart.addActionListener(this);
        jpanel1.add(btnStart);
        getRootPane().setDefaultButton(btnStart);
        btnCancel = new JButton("Cancel");
        btnCancel.setActionCommand("cancel");
        btnCancel.addActionListener(this);
        jpanel1.add(btnCancel);
        jpanel.add(jpanel1, gridbagconstraints);
        jpanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
        setContentPane(jpanel);
        pack();
        buttongroup.setSelected(btnFirstPlayer[0].getModel(), true);
    }

    public void setVisible(boolean flag)
    {
        if(flag)
            startPressed = false;
        super.setVisible(flag);
    }

    public boolean isStartPressed()
    {
        return startPressed;
    }

    public int getTurnLength()
    {
        return turnLength;
    }

    public String getAlgorithmName(int i)
    {
        return txtAlgorithm[i].getText();
    }

    public int getFirstPlayer()
    {
        return btnFirstPlayer[0].isSelected() ? 0 : 1;
    }

    public void actionPerformed(ActionEvent actionevent)
    {
        String s = actionevent.getActionCommand();
        if(s.equals("start"))
        {
            if(txtTurnLength.getText().length() == 0)
            {
                txtTurnLength.requestFocus();
                return;
            }
            try
            {
                turnLength = Integer.valueOf(txtTurnLength.getText()).intValue();
                if(turnLength < 1 || turnLength > 3600)
                    throw new NumberFormatException();
            }
            catch(NumberFormatException numberformatexception)
            {
                txtTurnLength.requestFocus();
                return;
            }
            startPressed = true;
            setVisible(false);
        } else
        if(s.equals("cancel"))
            setVisible(false);
    }

    JTextField txtTurnLength;
    JTextField txtAlgorithm[];
    JRadioButton btnFirstPlayer[];
    JButton btnStart;
    JButton btnCancel;
    boolean startPressed;
    int turnLength;
}